<?php
/**
 * Created by PhpStorm.
 * User: kcross
 * Date: 20-6-25
 * Time: 下午11:31
 */
namespace  App\Models\Forms;

use Illuminate\Database\Eloquent\Model;

class SystemConfig extends Model implements \App\Models\IReadable
{
    /**
     * 'taobao' => [
    'appkey' => '28344040',
    'secret' => "d861f4d173c628e355f40d307ff7c9a",
    'vekey' =>  env("taobao_vekey",'V00003649Y18996398'),
    'api_server' => env("taobao_api_server", 'http://api.vephp.com')
    ],
    'jd' => [
    'unionid' => '1002317478',
    'android_key' => 'f980aee5fe677d5695c5c4a5f4532439',
    'android_secret' => '35d19c976bfc45c9835153d3a09665e9',
    'api_server' =>  env("jd_api_server",'http://api.josapi.net')
    ],
    'pdd' => [
    'pid' => '9755386',
    'client_id' => '53510d06194a4f2da4b4b756ccb5840e',
    'client_secret' => 'f306f03ae352797852887728d627d2950969fcad',
    'api_server' => env("pdd_api_server", "http://gw-api.pinduoduo.com/api/router")
    ]
     */
    protected $table = "";

    public $id = 0;

    public function attributeLabels()
    {
        $res = [];
        $config = config("robot.spider");
        foreach ($config as $k => $item) {
            $title = "";
            switch ($k) {
                case "taobao":
                    $title = "淘宝";
                    break;
                case "jd":
                    $title = "京东";
                    break;
                case "pdd":
                    $title = "拼多多";
                    break;
            }
            foreach ($item as $kk => $value) {
                $res = array_merge($res, [
                    $kk => [
                        'label' =>  $title . $kk,
                        'value' => $value,
                        'type' => "text",
                        'disable' => true
                    ]
                ]);
            }
        }


        return $res;
    }

    public function getAttribute($field)
    {
        $res = $this->attributeLabels();
        return $res[$field]['value'];
    }

}